<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use http\Env\Response;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class FmwTaoBaoController extends Controller
{
    // WAIT_BUYER_PAY-等待买家付款;WAIT_SELLER_SEND_GOODS-买家已经付款;WAIT_BUYER_CONFIRM_GOODS-卖家已经发货;TRADE_FINISHED-交易成功;TRADE_CLOSED-交易自动关闭
    protected $orderStatus = 'WAIT_SELLER_SEND_GOODS';
    protected $approveStatus = 'onsale'; // onsale-出售中，instock-库中
    protected $skuId = 'SKUA00001';
    protected $skuId2 = 'SKUA00002';
    protected $numIid = '202411181850';

    public function index(Request $request)
    {
//        return response()->json([
//            "UpdateTime" => "2025-04-06 12:59:02",
//            "EBusinessID" => "1375910",
//            "Success" => false,
//            "Reason" => "业务错误[手机尾号不正确]"
//        ], 400);


        $method = $request->get('method');
        if (empty($method)) {
            return [];
        }
        $method = str_replace('.', '_', $method);

        if (!method_exists($this, $method)) {
            echo sprintf("[%s] mock function not exists", $method);
            exit;
        }

        return $this->$method($request);
    }

    public function token(Request $request)
    {
        $accessToken = date('YmdHis') . Str::random(6);

        return [
            "r1_expires_in" => 1800,
            "w1_expires_in" => 1800,
            "taobao_user_nick" => "商家测试帐号51",
            "expires_in" => 86400,
            "taobao_user_id" => "20250728",
            "access_token" => sprintf("tb_token_%s", $accessToken),
            "refresh_token" => sprintf("tb_refresh_token_%s", $accessToken),
            "token_type" => "Bearer",
            "api_name" => "",
            "w2_expires_in" => 0,
            "request_id" => "111",
            "r2_expires_in" => 0,
            "re_expires_in" => 0,
        ];
    }

    // 获取电子面单
    public function cainiao_waybill_ii_get(Request $request)
    {
        $requestData = $request->get('param_waybill_cloud_print_apply_new_request');
        if (empty($requestData)) {
            return [];
        }

        $responseData = [];
        $requestData = json_decode($requestData, true);
        foreach ($requestData['trade_order_info_dtos'] as $item) {
            $waybillCode = sprintf('XCXD_TB__%s', date('YmdHis', time()));
            $responseData[] = [
                'cp_code' => $requestData['cp_code'],
                'real_cp_code' => $requestData['cp_code'],
                'object_id' => $item['object_id'],
                'waybill_code' => $waybillCode,
                'print_data' => '{"data":{"_dataFrom":"waybill","adsInfo":{"adId":"3","advertisementType":"DEFAULT","bannerUrl":"http://ad-cdn.cainiao.com/3/1570692360541.jpg","miniBannerUrl":"http://ad-cdn.cainiao.com/3/1570692349536.jpg"},"cpCode":"POSTB","extraInfo":{},"needEncrypt":false,"packageInfo":{"goodsDescription":"照片以及相框产品","id":"668a56b652649965","items":[{"count":10,"name":"富士 冲印 绒面3.5x5寸 规格:C0186"}],"totalPackagesCount":1,"volume":1,"weight":1},"parent":false,"realCpCode":"POSTB","recipient":{"address":{"city":"黑河市","detail":"AES:GrfmVJkLCLTS15lERq6HRUBANQggjN6NK68oN938CEHNnDosVKeg9PkpduE+VM/8","province":"黑龙江省"},"mobile":"AES:OJWngOb2dZAZVaPK7A4qbg==","name":"AES:9qfECQo1Z0bKdnbHbG0HLA=="},"routingInfo":{"consolidation":{"name":"080黑A"},"origin":{"code":"POSTB"},"receiveBranch":{"code":"16146200","name":"黑龙江嫩江县中心"},"routeCode":"嫩江01 T02","sortation":{"name":"嫩江20-"},"startCenter":{},"terminalCenter":{},"villageTag":"1"},"sender":{"address":{"city":"广州市","detail":"沙头街道西丽工业园丽骏路15号9号楼西梯3楼","district":"番禺区","province":"广东省"},"mobile":"13433955571","name":"张晶雅","phone":"13433955571"},"shippingOption":{"code":"STANDARD_EXPRESS","title":"标准快递"},"waybillCode":"9887217864505"},"signature":"MD:PxZRHEFQVAC9/IeVJEvjtA==","templateURL":"http://cloudprint.cainiao.com/template/standard/288948/49"}'
            ];
        }

        $response = [
            'request_id' => '16mptg83y9hou',
            'cainiao_waybill_ii_get_response' => [
                'modules' => [
                    'waybill_cloud_print_response' => $responseData
                ]
            ]
        ];

//        $response = [
//            "error_response" => [
//                "msg" => "Remote service error",
//                "code" => 15,
//                "sub_msg" => "1:您好！受防疫措施变化影响，该目的地暂时无法提供此产品寄递服务，带来不便请您理解。(BPS5430)",
//                "sub_code" => "sf_response_fail-8177"
//            ]
//        ];

//        return response()->json([
//            "error_response" => [
//                "msg" => "Remote service error",
//                "code" => 15,
//                "sub_code" => "isv.oaid-invalid",
//                "sub_msg" => "[isv.oaid-invalid]:参数oaid无效，tid:3432484080503153057",
////                "sub_code" => "sf_response_fail-8177",
////                "sub_msg" => "1:您好！受防疫措施变化影响，该目的地暂时无法提供此产品寄递服务，带来不便请您理解。(BPS5430)",
//                "request_id" => "15rkjgoo134q7",
//            ]
//        ], 200);

        return $response;
    }

    public function cainiao_waybill_ii_cancel(Request $request)
    {
        $response = [
            'request_id' => '16mptg83y9hou',
            'cainiao_waybill_ii_cancel_response' => [
                'cancel_result' => true
            ]
        ];
        return $response;
    }

    public function taobao_items_onsale_get(Request $request)
    {
        $cid = 132443; // 商品所属的叶子类目 id
        $num = 8888; // 商品数量
        $valid_thru = 7; // 有效期,7或者14（默认是7天）
        $price = 5.00; // 商品价格，格式：5.00；单位：元；精确到：分

        $item = [
            "approve_status" => $this->approveStatus,
            "iid" => "13232",
            "num_iid" => $this->numIid,
            "title" => "Google test item",
            "nick" => "tbtest561",
            "type" => "fixed",
            "cid" => $cid,
            "seller_cids" => "2234445,3344466,446434",
            "pic_url" => "http://img03.taobao.net/bao/uploaded/i3/T1HXdXXgPSt0JxZ2.8_070458.jpg",
            "num" => $num,
            "props" => "135255:344454",
            "valid_thru" => $valid_thru,
            "list_time" => "2009-10-22 14:22:06",
            "price" => $price,
            "has_discount" => true,
            "has_invoice" => true,
            "has_warranty" => true,
            "has_showcase" => true,
            "modified" => "2000-01-01 00:00:00",
            "delist_time" => "2000-01-01 00:00:00",
            "postage_id" => 32,
            "outer_id" => 'outer_id_' . $this->numIid, // 商家外部编码
            "is_ex" => true,
            "is_virtual" => true,
            "is_taobao" => true,
            "sold_quantity" => 8888,
            "is_cspu" => true,
            "first_starts_time" => "2000-01-01 00:00:00"
        ];

        $item2 = $item;

        return [
            'request_id' => Str::random(16),
            'items_onsale_get_response' => [
                'total_results' => 1,
                'items' => [
                    'item' => [
                        $item
                    ]
                ]
            ]
        ];
    }

    public function taobao_items_seller_list_get(Request $request)
    {
        $cid = 132443; // 商品所属的叶子类目 id
        $item_img = [
            "created" => "2000-01-01 00:00:00",
            "id" => 1645920,
            "position" => 1,
            "url" => "http://img03.taobao.net/bao/uploaded/i3/T1HXdXXgPSt0JxZ2.8_070458.jpg"
        ];
        $prop_img = [
            "id" => 1646146,
            "position" => 1,
            "properties" => "1627207:28326",
            "url" => "http://img03.taobao.net/bao/uploaded/i3/T1HXdXXgPSt0JxZ2.8_070458.jpg"
        ];
        $sku = [
            "barcode" => "6903244981002",
            "created" => "2009-11-04 15:24:43",
            "modified" => "2009-11-04 15:24:43",
            "outer_id" => 'outer_id_' . $this->numIid, // 商家外部编码
            "price" => "200.07",
            "properties" => "1243:1215;5626:5125",
            "properties_name" => "20000:3275069:品牌:盈讯;1753146:3485013:型号:F908;-1234:-5678:自定义属性1:属性值1",
            "quantity" => 3,
            "sku_id" => $this->skuId,
            "sku_feature" => [
                "color_hot_new" => "热卖",
                "color_material_img" => "i3/2049872296/TB2VOVaXXXXXXXEXXXXXXXXXXXX_!!2049872296.jpg",
                "color_value" => "FF1493",
                "color_material" => "哑光",
                "color_series" => "正红色"
            ]
        ];
        $sku2 = $sku;
        $sku2['sku_id'] = $this->skuId . '111';

        $video = [
            "created" => "2000-01-01 00:00:00",
            "id" => 123456,
            "modified" => "2000-01-01 00:00:00",
            "url" => "http://js.tudouui.com/bin/taobaoisv/TaoBaoPlayer.swf……",
            "video_id" => 123456
        ];
        $item_img1 = [
            "position" => 0,
            "url" => "http://img03.taobao.net/bao/uploaded/i3/T1HXdXXgPSt0JxZ2.8_070458.jpg"
        ];

        $item = [
            "after_sale_id" => 123,
            "approve_status" => $this->approveStatus,
            "auction_point" => 15,
            "auto_fill" => "time_card",
            "auto_repost" => true,
            "barcode" => "6903244981002",
            "cid" => $cid,
            "cod_postage_id" => 53899,
            "created" => "2000-01-01 00:00:00",
            "custom_made_type_id" => "1",
            "delist_time" => "2000-01-01 00:00:00",
            "desc" => "这是一个好商品",
            "desc_module_info" => [
                "anchor_module_ids" => "1,4,7",
                "type" => 1
            ],
            "detail_url" => "http://item.taobao.com/item.htm?id=4947813209",
            "ems_fee" => "5.00",
            "express_fee" => "5.00",
            "features" => ";tags:3522,7234;source:sell;sp:2;",
            "food_security" => [
                "contact" => "00800-021216",
                "design_code" => "Q/DHL.001-2008",
                "factory" => "远东恒天然乳品有限公司",
                "factory_site" => "台北市仁爱路4段85号",
                "food_additive" => "磷脂 、膨松剂",
                "health_product_no" => "卫食健字(1997)第167号",
                "mix" => "有机乳糖、有机植物油",
                "period" => "2年",
                "plan_storage" => "常温",
                "prd_license_no" => "QS410006010388",
                "product_date_end" => "2012-06-10",
                "product_date_start" => "2012-06-01",
                "stock_date_end" => "2012-06-30",
                "stock_date_start" => "2012-06-20",
                "supplier" => "深圳岸通商贸有限公司"
            ],
            "freight_payer" => "seller",
            "global_stock_country" => "美国",
            "global_stock_type" => "1",
            "has_discount" => true,
            "has_invoice" => true,
            "has_showcase" => true,
            "has_warranty" => true,
            "increment" => "0",
            "inner_shop_auction_template_id" => 2185480,
            "input_pids" => "2432,5353,656425",
            "input_str" => "耐克;耐克系列;科比系列;科比系列;2K5",
            "is_3D" => true,
            "is_ex" => true,
            "is_fenxiao" => 0,
            "is_lightning_consignment" => true,
            "is_prepay" => true,
            "is_taobao" => true,
            "is_timing" => true,
            "is_virtual" => true,
            "is_xinpin" => false,
            "item_imgs" => [
                'item_img' => [
                    $item_img
                ]
            ],
            "item_size" => "bulk:10",
            "item_weight" => "10",
            "list_time" => "2009-10-22 14:22:06",
            "locality_life" => [
                "choose_logis" => "0",
                "eticket" => ";market:eticket;refundmafee:b;",
                "expirydate" => "2012-08-06,2012-08-16",
                "merchant" => "56879:码商X",
                "network_id" => "5645746",
                "onsale_auto_refund_ratio" => 80,
                "refund_ratio" => 50,
                "refundmafee" => "b",
                "verification" => "1"
            ],
            "location" => [
                "city" => "杭州",
                "state" => "浙江"
            ],
            "modified" => "2000-01-01 00:00:00",
            "mpic_video" => [
                "num_iid" => $this->numIid,
                "video_duaration" => 9,
                "video_id" => 9527,
                "video_pic" => "http://img02.taobaocdn.com/bao/uploaded/T14rGfFqJfXXXXXXXX.jpg",
                "video_status" => 0
            ],
            "newprepay" => "1",
            "nick" => "tbtest561",
            "num" => 8888,
            "num_iid" => $this->numIid,
            "one_station" => true,
            "outer_id" => "34143554352",
            "outer_shop_auction_template_id" => 2185481,
            "paimai_info" => [
                "deposit" => 20,
                "increment" => "5",
                "interval" => 5,
                "mode" => 1,
                "reserve" => "12.0",
                "valid_hour" => 20,
                "valid_minute" => 23,
                "repeat" => 1,
                "start" => "2009-11-04 15:24:43",
                "end" => "2009-11-04 15:24:43",
                "start_price" => 1000,
                "ceil_price" => 20000,
                "delay_in_minute" => 5,
                "period" => 55,
                "frequency" => 5
            ],
            "period_sold_quantity" => 100,
            "pic_url" => "http://img03.taobao.net/bao/uploaded/i3/T1HXdXXgPSt0JxZ2.8_070458.jpg",
            "post_fee" => "5.00",
            "postage_id" => 32,
            "price" => "5.00",
            "product_id" => 85883030,
            "promoted_service" => "2",
            "prop_imgs" => [
                "prop_img" => [
                    $prop_img
                ]
            ],
            "property_alias" => "property:111:222",
            "props" => "135255:344454",
            "props_name" => "20000:3275069:品牌:盈讯;1753146:3485013:型号:F908;30606:112030:上市时间:2008年",
            "score" => 2,
            "second_kill" => "web_only",
            "sell_point" => "2013新款 时尚 前卫",
            "sell_promise" => true,
            "seller_cids" => "2234445,3344466,446434",
            "skus" => [
                'sku' => [
                    $sku, $sku2
                ]
            ],
            "sold_quantity" => 8888,
            "stuff_status" => "new",
            "sub_stock" => 1,
            "template_id" => "123456",
            "title" => "Google test item",
            "type" => "fixed",
            "valid_thru" => 7,
            "video_id" => 9527,
            "videos" => [
                "video" => [
                    $video
                ]
            ],
            "violation" => true,
            "volume" => 22,
            "wap_desc" => "Wap宝贝详情",
            "wap_detail_url" => "http://auction1.wap.taobao.com/auction/item_detail-0db0-1234567.jhtml",
            "wireless_desc" => "无线宝贝描述，亲",
            "with_hold_quantity" => 12,
            "ww_status" => true,
            "desc_modules" => "[{\"module_id\":123,\"module_name\":\"模特图\",\"type\":\"cat_mod\",\"content\":\"模特要漂亮一点拜托\"},{\"module_id\":null,\"module_name\":\"店主最漂亮\",\"type\":\"usr_mod\",\"content\":\"老娘全网最美\"}]",
            "cuntao_item_specific" => [
                "kick_back_rate" => "3.3即3.3%佣金率"
            ],
            "item_rectangle_imgs" => [
                'item_img' => [
                    $item_img1
                ]
            ]
        ];

        return [
            'request_id' => Str::random(16),
            'items_seller_list_get_response' => [
                'items' => [
                    'item' => [
                        $item
                    ]
                ]
            ]
        ];
    }

    public function taobao_skus_custom_get(Request $request)
    {
        $item = [
            "sku_id" => $this->skuId,
            "iid" => "asdf12323adfaa",
            "properties" => "1243:1215;5626:5125",
            "properties_name" => "20000:3275069:品牌:盈讯;1753146:3485013:型号:F908;-1234:-5678:自定义属性1:属性值1",
            "quantity" => 3,
            "price" => "200.07",
            "outer_id" => $request->get('outer_id', '12345'),
            "created" => "2009-11-04 15:24:43",
            "modified" => "2009-11-04 15:24:43",
            "status" => "normal",
            "num_iid" => $this->numIid,
        ];

        return [
            'request_id' => Str::random(16),
            'skus_custom_get_response' => [
                'skus' => [
                    'sku' => [
                        $item
                    ]
                ]
            ]
        ];
    }

    public function taobao_trade_fullinfo_get(Request $request)
    {
        $tid = $request->get('tid', '');

//        // 送礼人支付运费订单
//        $orderInfo = '{"trade_fullinfo_get_response":{"trade":{"seller_open_uid":"AAGpt7DQAA_spZaeCv6nsJaX","buyer_open_uid":"AAEDt7DQAA_spZaeCv6e2lMT","tid":2463093770092510700,"tid_str":"2463093770092510752","status":"WAIT_SELLER_SEND_GOODS","type":"fixed","seller_nick":"富士官方旗舰店","buyer_nick":"l**","created":"2025-02-10 16:57:43","oaid":"1uDabfQTLiaCSnpZ05p9eay3rIuTk1jGSyrdGn4jr1RJsxXIOgDQhh7Vj1ld1MeOlb1wu3jF","real_receiver_open_id":"AAEMt7DQAA_spZaeCv6KPmm2","real_receiver_display_nick":"l**","post_fee_type":"giftprepaid","real_post_fee":"1200","refund_post_fee":"800","gift_post_fee_role":"0","extend_info":"{\"privacy\":\"1\"}","modified":"2025-02-10 17:00:10","delay_create_delivery":0,"ofp_hold":0,"trade_attr":"{\"erpHold\":\"0\",\"cnService\":\"84_50\"}","adjust_fee":"0.00","alipay_no":"2025021022001150521435535532","alipay_point":0,"available_confirm_fee":"100.00","buyer_alipay_no":"****","buyer_area":"未知","buyer_cod_fee":"0.00","buyer_email":"****","buyer_obtain_point_fee":0,"buyer_rate":false,"can_rate":false,"credit_card_fee":"108.00","cod_fee":"0.00","cod_status":"NEW_CREATED","coupon_fee":0,"commission_fee":"0.00","discount_fee":"0.00","has_post_fee":true,"has_yfx":false,"is_3D":false,"is_brand_sale":false,"is_daixiao":false,"is_force_wlb":false,"is_sh_ship":false,"is_lgtype":false,"is_part_consign":false,"is_wt":false,"is_gfjy":false,"is_gift":false,"is_cycle_buy":false,"num":1,"num_iid":660962044105,"new_presell":false,"nr_shop_guide_id":"","nr_shop_guide_name":"","orders":{"order":[{"adjust_fee":"0.00","buyer_rate":false,"cid":50008681,"consign_due_time":"2_2","discount_fee":"50.00","divide_order_fee":"88.00","extend_info":"{\"privacy\":\"1\"}","is_bybt_order":false,"is_daixiao":false,"is_idle":"0","is_jzfx":false,"is_oversold":false,"is_sh_ship":false,"num":1,"num_iid":660962044105,"oid":2463093770092510700,"oid_str":"2463093770092510752","order_attr":"{\"cnService\":\"84_50\"}","order_from":"WAP,WAP","outer_sku_id":"6970967593430","payment":"108.00","pic_path":"https://img.alicdn.com/bao/uploaded/i2/1019803011/O1CN01CQEBiw1Y75H5c0dDd_!!1019803011.jpg","price":"138.00","refund_status":"NO_REFUND","seller_rate":false,"seller_type":"B","shipper":"cn","sku_id":"4945979691492","sku_properties_name":"颜色分类:补光灯","snapshot_url":"y:2463093770092510752_1","special_refund_type":"returnPartPostage","status":"WAIT_SELLER_SEND_GOODS","store_code":"SHA216","title":"Fujifilm/富士instax一次成像正品原装instax mini Evo一次成像相机配件磁吸RGB补光灯适用","total_fee":"88.00"}]},"pay_time":"2025-02-10 16:57:50","payment":"108.00","pcc_af":0,"pic_path":"https://img.alicdn.com/bao/uploaded/i2/1019803011/O1CN01CQEBiw1Y75H5c0dDd_!!1019803011.jpg","platform_subsidy_fee":"0.00","point_fee":0,"post_fee":"20.00","price":"138.00","promotion_details":{"promotion_detail":[{"discount_fee":"50.00","id":2463093770092510700,"kd_discount_fee":"50.00","promotion_desc":"掌柜推荐:省50.00元","promotion_id":"Tmall$commonItemPromotion-30383658294_544660560017","promotion_name":"掌柜推荐"}]},"q_r_pay":false,"real_point_fee":0,"received_payment":"0.00","receiver_address":"王**乡 **路垡头***号，**公寓*区***","receiver_city":"北京市","receiver_country":"","receiver_district":"朝阳区","receiver_mobile":"***********","receiver_name":"李**","receiver_state":"北京","receiver_town":"王四营乡","receiver_zip":"000000","seller_alipay_no":"***ifilm_2022@xcxd.com","seller_can_rate":false,"seller_cod_fee":"0.00","seller_email":"fujifilm_2022@xcxd.com","seller_flag":0,"seller_mobile":"17051007642","seller_rate":false,"service_tags":{"logistics_tag":[{"logistic_service_tag_list":{"logistic_service_tag":[{"service_tag":"forUser=true;esDate=2025-02-13;capUpgrade=true;origAreaId=110105;capPeriod=1080;capDate=2025-02-11;capAreaId=110105042;matrix=true;capType=100;esTime=3","service_type":"100"}]},"order_id":"2463093770092510752"},{"logistic_service_tag_list":{"logistic_service_tag":[{"service_tag":"forUser=true;capGroup=0;capOwner=1019803011;cycleCat=20;esRange=00:00-23:59;cycleVal=2;ssid=5000000000014;esTime=3;cutoffMinutes=1080;esDate=2025-02-13;logisPattern=std;cutTime=18;eas=702-2020018;ebs=84-2010001;capService=2010001;lineTime=2880;mcTime=1080;capPeriod=1080;capDate=2025-02-11;ldsc=1;cnService=84;storeCode=SHA216;ts=cnunionTwoDayReach;needLine=true","service_type":"cdc"}]},"order_id":"2463093770092510752"}]},"service_type":"","shipping_type":"express","sid":"2463093770092510752","snapshot_url":"y:2463093770092510752_1","title":"富士官方旗舰店","total_fee":"138.00","trade_from":"WAP,WAP","tmall_coupon_fee":0,"v_logistics_create":false,"you_xiang":false,"payment_method":"alipay"}}}';
//        // 收礼人支付运费
//        $orderInfo = '{"trade_fullinfo_get_response":{"trade":{"seller_open_uid":"AAGpt7DQAA_spZaeCv6nsJaX","buyer_open_uid":"AAEDt7DQAA_spZaeCv6e2lMT","tid":2462852280654510600,"tid_str":"2462852280654510752","status":"WAIT_SELLER_SEND_GOODS","type":"fixed","seller_nick":"富士官方旗舰店","buyer_nick":"l**","created":"2025-02-10 17:35:49","oaid":"1uDabfQTLiaCSnpZ05p9eay3rIuTk1jGSyrdGn4jr1RJsxXIOgDQhh7Vj1ld1MeOlb1wu3jF","real_receiver_open_id":"AAEMt7DQAA_spZaeCv6KPmm2","real_receiver_display_nick":"l**","post_fee_type":"giftprepaid","real_post_fee":"1200","refund_post_fee":"800","gift_post_fee_role":"1","extend_info":"{\"privacy\":\"1\"}","modified":"2025-02-10 17:40:17","delay_create_delivery":0,"ofp_hold":0,"trade_attr":"{\"erpHold\":\"0\",\"cnService\":\"84_50\"}","adjust_fee":"0.00","alipay_no":"2025021022001150521439535715","alipay_point":0,"available_confirm_fee":"100.00","buyer_alipay_no":"****","buyer_area":"未知","buyer_cod_fee":"0.00","buyer_email":"****","buyer_obtain_point_fee":0,"buyer_rate":false,"can_rate":false,"credit_card_fee":"88.00","cod_fee":"0.00","cod_status":"NEW_CREATED","coupon_fee":0,"commission_fee":"0.00","discount_fee":"0.00","has_post_fee":true,"has_yfx":false,"is_3D":false,"is_brand_sale":false,"is_daixiao":false,"is_force_wlb":false,"is_sh_ship":false,"is_lgtype":false,"is_part_consign":false,"is_wt":false,"is_gfjy":false,"is_gift":false,"is_cycle_buy":false,"num":1,"num_iid":660962044105,"new_presell":false,"nr_shop_guide_id":"","nr_shop_guide_name":"","orders":{"order":[{"adjust_fee":"0.00","buyer_rate":false,"cid":50008681,"consign_due_time":"2_2","discount_fee":"50.00","divide_order_fee":"88.00","extend_info":"{\"privacy\":\"1\"}","is_bybt_order":false,"is_daixiao":false,"is_idle":"0","is_jzfx":false,"is_oversold":false,"is_sh_ship":false,"num":1,"num_iid":660962044105,"oid":2462852280654510600,"oid_str":"2462852280654510752","order_attr":"{\"cnService\":\"84_50\"}","order_from":"WAP,WAP","outer_sku_id":"6970967593430","payment":"108.00","pic_path":"https://img.alicdn.com/bao/uploaded/i2/1019803011/O1CN01CQEBiw1Y75H5c0dDd_!!1019803011.jpg","price":"138.00","refund_status":"NO_REFUND","seller_rate":false,"seller_type":"B","shipper":"cn","sku_id":"4945979691492","sku_properties_name":"颜色分类:补光灯","snapshot_url":"y:2462852280654510752_1","special_refund_type":"returnPartPostage","status":"WAIT_SELLER_SEND_GOODS","store_code":"SHA216","title":"Fujifilm/富士instax一次成像正品原装instax mini Evo一次成像相机配件磁吸RGB补光灯适用","total_fee":"88.00"}]},"pay_time":"2025-02-10 17:36:06","payment":"108.00","pcc_af":0,"pic_path":"https://img.alicdn.com/bao/uploaded/i2/1019803011/O1CN01CQEBiw1Y75H5c0dDd_!!1019803011.jpg","platform_subsidy_fee":"0.00","point_fee":0,"post_fee":"20.00","price":"138.00","promotion_details":{"promotion_detail":[{"discount_fee":"50.00","id":2462852280654510600,"kd_discount_fee":"50.00","promotion_desc":"掌柜推荐:省50.00元","promotion_id":"Tmall$commonItemPromotion-30383658294_544660560017","promotion_name":"掌柜推荐"}]},"q_r_pay":false,"real_point_fee":0,"received_payment":"0.00","receiver_address":"王**乡 **路垡头***号，**公寓*区***","receiver_city":"北京市","receiver_country":"","receiver_district":"朝阳区","receiver_mobile":"***********","receiver_name":"李**","receiver_state":"北京","receiver_town":"王四营乡","receiver_zip":"000000","seller_alipay_no":"***ifilm_2022@xcxd.com","seller_can_rate":false,"seller_cod_fee":"0.00","seller_email":"fujifilm_2022@xcxd.com","seller_flag":0,"seller_mobile":"17051007642","seller_rate":false,"service_tags":{"logistics_tag":[{"logistic_service_tag_list":{"logistic_service_tag":[{"service_tag":"forUser=true;esDate=2025-02-13;capUpgrade=true;origAreaId=110105;capPeriod=1080;capDate=2025-02-11;capAreaId=110105042;matrix=true;capType=100;esTime=3","service_type":"100"}]},"order_id":"2462852280654510752"},{"logistic_service_tag_list":{"logistic_service_tag":[{"service_tag":"forUser=true;capGroup=0;capOwner=1019803011;cycleCat=20;esRange=00:00-23:59;cycleVal=2;ssid=5000000000014;esTime=3;cutoffMinutes=1080;esDate=2025-02-13;logisPattern=std;cutTime=18;eas=702-2020018;ebs=84-2010001;capService=2010001;lineTime=2880;mcTime=1080;capPeriod=1080;capDate=2025-02-11;ldsc=1;cnService=84;storeCode=SHA216;ts=cnunionTwoDayReach;needLine=true","service_type":"cdc"}]},"order_id":"2462852280654510752"}]},"service_type":"","shipping_type":"express","sid":"2462852280654510752","snapshot_url":"y:2462852280654510752_1","title":"富士官方旗舰店","total_fee":"138.00","trade_from":"WAP,WAP","tmall_coupon_fee":0,"v_logistics_create":false,"you_xiang":false,"payment_method":"alipay"}}}';
//        $orderInfo = json_decode($orderInfo, true);
//        $orderInfo['trade_fullinfo_get_response']['trade']['tid'] = $tid;
//        $orders = $orderInfo['trade_fullinfo_get_response']['trade']['orders']['order'] ?? [];
//        foreach ($orders as $key => &$order) {
//            $order['sku_id'] = ($key == 0) ? '202506260001' : '202506260002';
//            $order['outer_sku_id'] = ($key == 0) ? $this->skuId : $this->skuId2;
//            $order['outer_iid'] = $this->numIid;
//        }
//        $orderInfo['trade_fullinfo_get_response']['trade']['orders']['order'] = $orders;
//        return $orderInfo;

        $discountFee = 100;
        $order1 = [
            "adjust_fee" => "0.00",
            "buyer_rate" => false,
            "cid" => 50003794,
            "consign_time" => "2022-06-22 11:30:52",
            "discount_fee" => $discountFee,
            "divide_order_fee" => "4500.00",
            "end_time" => "2022-06-22 11:32:39",
            "et_shop_name" => "上海宝旅(39892)",
            "invoice_no" => "0000",
            "is_daixiao" => false,
            "is_idle" => "0",
            "is_oversold" => false,
            "logistics_company" => "电子凭证",
            "nr_outer_iid" => "MT-F 750 GS2",
            "num" => 1,
            "num_iid" => 621778268817,
            "oid" => 159624580840708004,
            "outer_sku_id" => $this->skuId,
            "outer_iid" => $this->numIid,
            "oid_str" => "159624580840708004",
            "sku_id" => "202506260001",
            "gov_sn_check" => "1_1_1",
            "order_attr" => "{\"mobile\":\"18117101022\"}",
            "order_from" => "WAP,WAP",
            "payment" => "4500.00",
            "pic_path" => "https://img.alicdn.com/bao/uploaded/i4/2207685574077/O1CN01n4E4Uv1fzJWMduOgN_!!0-item_pic.jpg",
            "price" => "7500.00",
            "refund_status" => "NO_REFUND",
            "seller_rate" => false,
            "seller_type" => "B",
            "shipping_type" => "express",
            "snapshot_url" => "u:159624580840708004_1",
            "status" => "WAIT_BUYER_PAY",
            "title" => "宝马/BMW摩托车官方旗舰店 BMW F 750 GS 摩托车购车订金券",
            "total_fee" => "4500.00",
            "sub_order_tax_fee" => "100.00",
            "part_mjz_discount" => "70.00",
        ];

        $order2 = $order1;
        $order2['payment'] = 3000;
        $order2['total_fee'] = 3000;
        $order2['oid'] = '202505141537001';
        $order2['outer_sku_id'] = $this->skuId2;
        $order2['sku_id'] = '202506260002';
        $order2['sub_order_tax_fee'] = 0;
        $order2['part_mjz_discount'] = 20;

        $logisticsInfo = [
            "biz_delivery_type" => 2,
            "sub_trade_id" => 2485842639169511000,
            "trade_id" => 2485842639168511000,
            "white_delivery_cps" => "YTO"
        ];

        return [
            'trade_fullinfo_get_response' => [
                'trade' => [
                    "tid" => $tid,
                    "tid_str" => (string)$tid,
                    "status" => $this->orderStatus,
                    "type" => "fixed", // step、fixed
                    "seller_nick" => "富士官方旗舰店",
                    "buyer_nick" => "测试用户名称",
                    "created" => date('Y-m-d H:i:s'),
                    "modified" => date('Y-m-d H:i:s'),
                    "pay_time" => date('Y-m-d H:i:s'),
                    "adjust_fee" => "0.00",
                    "alipay_no" => "2022062222001113401407440445",
                    "oaid" => "1ab3z4V53S1fILhIrewrFNsBSibpcN4Lcib75ib4Q1R6OlbGQ91fjkRSkJbKGuz51XOzDdl7x4",
                    "alipay_point" => 0,
                    "available_confirm_fee" => "0.00",
                    "real_receiver_open_id" => 'AAEMt7DQAA_spZaeCv6KPmm2',
                    "real_receiver_display_nick" => '测试用户**',
                    "post_fee" => "20.00", // 运费（单位元）
                    "real_post_fee" => "1200", // 实际运费（单位分）
                    "refund_post_fee" => "800", // 退款运费（单位分）
                    "gift_post_fee_role" => 0, // 运费付款方式：0-送礼人支付；1-收件人支付
                    "payment_method" => "wx", // 订单支付方式，wx为微信支付，alipay为支付宝支付，others为其他支付方式
                    "payment" => "7520.00",
                    "price" => "7520.00",
                    "total_fee" => "7520.00",
                    "received_payment" => "7520.00",
                    "buyer_alipay_no" => "***381824345@sina.com",
                    "buyer_area" => "上海上海联通",
                    "buyer_cod_fee" => "0.00",
                    "buyer_email" => "",
                    "buyer_obtain_point_fee" => 750,
                    "buyer_rate" => false,
                    "can_rate" => true,
                    "credit_card_fee" => "7490.00",
                    "cod_fee" => "0.00",
                    "cod_status" => "NEW_CREATED",
                    "coupon_fee" => 0,
                    "commission_fee" => "300.00",
                    "consign_time" => "2022-06-22 11:30:52",
                    "discount_fee" => $discountFee,
                    "end_time" => "2022-06-22 11:32:39",
                    "et_shop_id" => 290400140,
                    "has_post_fee" => true,
                    "has_yfx" => false,
                    "is_3D" => false,
                    "is_brand_sale" => false,
                    "is_daixiao" => false,
                    "is_force_wlb" => false,
                    "is_sh_ship" => false,
                    "is_lgtype" => false,
                    "is_part_consign" => false,
                    "is_wt" => false,
                    "is_gift" => false,
                    "market" => "eticket",
                    "num" => 1,
                    "num_iid" => 621778268817,
                    "new_presell" => false,
                    "nr_shop_guide_id" => "",
                    "nr_shop_guide_name" => "",
                    "obs" => "1",
                    "orders" => [
                        "order" => [
                            $order1, $order2
                        ]
                    ],
                    "logistics_agreement" => [
                        "asdp_ads" => "209",
                        "asdp_biz_type" => "aox",
                        "logistics_service_msg" => "自选快递"
                    ],
                    "logistics_infos" => [
                        'logistics_info' => [
                            $logisticsInfo
                        ],
                    ],
                    "pcc_af" => 0,
                    "pic_path" => "https://img.alicdn.com/bao/uploaded/i4/2207685574077/O1CN01n4E4Uv1fzJWMduOgN_!!0-item_pic.jpg",
                    "platform_subsidy_fee" => "0.00",
                    "point_fee" => 0,
                    "q_r_pay" => false,
                    "real_point_fee" => 0,
                    "receiver_country" => "",
                    "receiver_name" => "收货人名称",
                    "receiver_phone" => "18117101022",
                    "receiver_mobile" => "18117101022",
                    "receiver_address" => "朝阳合生汇",
                    "receiver_state" => "",
                    "receiver_zip" => "000000",
                    "seller_alipay_no" => "***_motorrad1@xcxd.com",
                    "seller_can_rate" => true,
                    "seller_cod_fee" => "0.00",
                    "seller_email" => "bmw_motorrad1@xcxd.com",
                    "seller_mobile" => "15210447738",
                    "seller_name" => "北京兴长信达科技发展有限公司",
                    "seller_rate" => false,
                    "buyer_flag" => 1,
                    "buyer_memo" => "上衣要大一号",
                    "seller_memo" => "好的",
                    "seller_flag" => 1,
                    "service_tags" => [],
                    "service_type" => "",
                    "shipping_type" => "express",
                    "sid" => "159624580840708004",
                    "snapshot_url" => "u:159624580840708004_1",
                    "title" => "BMW摩托车官方旗舰店",
                    "trade_from" => "WAP,WAP",
                    "v_logistics_create" => false,
                    "you_xiang" => false
                ]
            ]
        ];
    }

    // 自己联系物流发货
    public function alibaba_ascp_logistics_offline_send()
    {
        return [
            'alibaba_ascp_logistics_offline_send_response' => [
                'result' => [
                    'success' => true,
                ]
            ]
        ];
    }

    public function taobao_logistics_dummy_send()
    {
//        return [
//            'logistics_dummy_send_response' => [
//                'shipping' => ['is_success' => true]
//            ]
//        ];

        return response([
            'error_response' => [
                'code' => 15,
                'msg' => 'Remote service error',
//                'sub_code' => 'DUMMY_CATEGORY_LIST111',
                'sub_code' => 'DUMMY_CATEGORY_LIST',
                'sub_msg' => '请选择合理的发货方式，实物商品逐步关闭无需物流发货方式。',
                'request_id' => '15t1t25s476iy',
            ]
        ], 200);
    }

    public function taobao_trades_sold_increment_get(Request $request)
    {
        $page = $request->get('page_no', 1);
        $oid = sprintf('mock_%s%s', date('YmdHis'), Str::random(6));
        $oid = 'FSOMS20241227719493';
        $discountFee = 100;
        $skuId = '202403150001';
//        $skuId = sprintf('%s%s%s', Str::random(3), date('YmdHis'), Str::random(3));
        $created = date('Y-m-d H:i:s', strtotime(sprintf('-%s hour', rand(2, 72))));
        $payTime = date('Y-m-d H:i:s', strtotime('+1 hour', strtotime($created)));

        $orderItem = [
            "adjust_fee" => "0.00",
            "buyer_rate" => false,
            "cid" => 211708,
            "collect_time" => "2024-01-15 23:59:59",
            "consign_time" => "2024-01-15 15:48:34",
            "cutoff_minutes" => "1020",
            "delivery_time" => "2024-01-15 23:59:59",
            "discount_fee" => $discountFee,
            "divide_order_fee" => "158.80",
            "extend_info" => "{\"privacy\":\"2\"}",
            "invoice_no" => "78762822517576",
            "is_daixiao" => false,
            "is_idle" => "0",
            "is_jzfx" => false,
            "is_oversold" => false,
            "logistics_company" => "中通快递",
            "num" => 1,
            "num_iid" => 739623344429,
            "oid" => $oid,
            "oid_str" => $oid,
            "order_from" => "WAP,WAP",
            "outer_sku_id" => "6949669313424",
            "payment" => "158.80",
            "pic_path" => "https://img.alicdn.com/bao/uploaded/i3/2216546893452/O1CN01ujQMIR1bN46JrZeng_!!2216546893452.jpg",
            "price" => "158.80",
            "promise_collect_time" => "2024-01-15 23:59:59",
            "refund_status" => "NO_REFUND",
            "seller_rate" => false,
            "seller_type" => "C",
            "ship_info" => [],
            "shipping_type" => "express",
            "sku_id" => $skuId,
            "sku_properties_name" => "颜色分类:蓝色991CNX[【限时特价】]",
            "snapshot_url" => sprintf('w:%s_1', $oid),
            "status" => $this->orderStatus,
            "timeout_action_time" => "2024-01-25 15:48:34",
            "timing_promise" => "1001",
            "title" => "卡西欧计算器FX-991CN X高中大学生考研考试计算机中文版竞赛函数",
            "total_fee" => "158.80"
        ];

        $order = [
            "buyer_open_uid" => "AAGct7DQAA_spZaeCv4-oAeS",
            "tid" => $oid,
            "tid_str" => $oid,
            "status" => $this->orderStatus,
            "type" => "fixed",
            "seller_nick" => "tb722116253674",
            "buyer_nick" => "桃**",
            "created" => $created,
            "oaid" => "1ab3z4V53S1fILhIrewrFNsBSibpcN4Lcib75ib4Q1R6OlbGQ91fjkRSkJbKGuz51XOzDdl7x4",
            "extend_info" => "{\"privacy\":\"2\"}",
            "modified" => "2024-01-15 15:50:30",
            "trade_attr" => "{\"cutoffMinutes\":\"1020\",\"collectTime\":\"2024-01-15 23:59:59\",\"deliveryTime\":\"2024-01-15 23:59:59\",\"erpHold\":\"0\"}",
            "adjust_fee" => "0.00",
            "asdp_ads" => "203",
            "asdp_biz_type" => "logistics_upgrade",
            "alipay_no" => "2024011522001134821455566232",
            "alipay_point" => 0,
            "available_confirm_fee" => "158.80",
            "buyer_alipay_no" => "****",
            "buyer_area" => "福建电信",
            "buyer_cod_fee" => "0.00",
            "buyer_email" => "****",
            "buyer_obtain_point_fee" => 0,
            "buyer_rate" => false,
            "can_rate" => false,
            "cod_fee" => "0.00",
            "cod_status" => "NEW_CREATED",
            "coupon_fee" => 0,
            "commission_fee" => "0.00",
            "consign_time" => "2024-01-15 15:48:34",
            "discount_fee" => $discountFee,
            "delivery_time" => "2024-01-15 23:59:59",
            "has_post_fee" => true,
            "has_yfx" => false,
            "is_3D" => false,
            "is_brand_sale" => false,
            "is_daixiao" => false,
            "is_force_wlb" => false,
            "is_sh_ship" => false,
            "is_lgtype" => false,
            "is_part_consign" => false,
            "is_wt" => false,
            "is_gift" => false,
            "is_cycle_buy" => false,
            "num" => 1,
            "num_iid" => 739623344429,
            "new_presell" => false,
            "nr_shop_guide_id" => "",
            "nr_shop_guide_name" => "",
            "orders" => [
                'order' => [
                    $orderItem
                ]
            ],
            "pay_time" => $payTime,
            "payment" => "158.80",
            "pcc_af" => 0,
            "pic_path" => "https://img.alicdn.com/bao/uploaded/i3/2216546893452/O1CN01ujQMIR1bN46JrZeng_!!2216546893452.jpg",
            "platform_subsidy_fee" => "0.00",
            "point_fee" => 0,
            "post_fee" => "0.00",
            "price" => "158.80",
            "q_r_pay" => false,
            "real_point_fee" => 0,
            "received_payment" => "0.00",
            "receiver_address" => "小**街道塔北**道金**园【***********-****】",
            "receiver_city" => "邵阳市",
            "receiver_country" => "",
            "receiver_district" => "双清区",
            "receiver_mobile" => "*******4993",
            "receiver_name" => "罗**",
            "receiver_state" => "湖南省",
            "receiver_town" => "小江湖街道",
            "receiver_zip" => "000000",
            "seller_alipay_no" => "157******80",
            "seller_can_rate" => false,
            "seller_cod_fee" => "0.00",
            "seller_email" => "",
            "seller_flag" => 0,
            "seller_mobile" => "15724750780",
            "seller_rate" => false,
            "send_time" => "2024-01-15",
            "service_tags" => [],
            "service_type" => "",
            "shipping_type" => "express",
            "sid" => $oid,
            "snapshot_url" => sprintf('w:%s_1', $oid),
            "timeout_action_time" => "2024-01-25 15:48:34",
            "title" => "中国教育考试基地",
            "total_fee" => "158.80",
            "trade_from" => "WAP,WAP",
            "tmall_coupon_fee" => 0,
            "v_logistics_create" => false,
            "you_xiang" => false,
            "timing_promise" => "1001"
        ];

        return [
            "trades_sold_increment_get_response" => [
                "total_results" => 2,
                "trades" => [
                    "trade" => [
                        $order,
                    ]
                ],
                "has_next" => $page < rand(2, 5),
            ]
        ];
    }

    public function taobao_shop_seller_get()
    {
//        return [
//            "error_response" => [
//                "msg" => "Invalid Session",
//                "code" => 27,
//                "sub_msg" => "无效的SessionKey参数",
//                "sub_code" => "Invalid Session",
//            ]
//        ];
        return [
            'shop_seller_get_response' => [
                'shop' => [
                    "sid" => 44750468,
                    "title" => "我的店铺",
                    "pic_path" => "/e2/c0/T1KVXXXhGvt0L1upjX.jpg"
                ],
            ],
        ];
    }

    public function taobao_user_seller_get()
    {
        return [
            'user_seller_get_response' => [
                'user' => [
                    "user_id" => 10001,
                    "nick" => "hz0799",
                    "sex" => "m",
                    "seller_credit" => [
                        "level" => 1,
                        "score" => 1,
                        "total_num" => 1,
                        "good_num" => 1
                    ],
                    "type" => "B",
                    "has_more_pic" => true,
                    "item_img_num" => 5,
                    "item_img_size" => 1024,
                    "prop_img_num" => 5,
                    "prop_img_size" => 1024,
                    "auto_repost" => "unlimited",
                    "promoted_type" => "authentication",
                    "status" => "normal",
                    "alipay_bind" => "bind",
                    "consumer_protection" => true,
                    "vip_info" => "v1",
                    "magazine_subscribe" => true,
                    "vertical_market" => "3C,shoes",
                    "avatar" => "http://assets.taobaocdn.com/app/sns/img/default/avatar-120.png",
                    "online_gaming" => true,
                    "liangpin" => true,
                    "sign_food_seller_promise" => true,
                    "has_shop" => true,
                    "is_lightning_consignment" => true,
                    "has_sub_stock" => true,
                    "is_golden_seller" => true,
                    "is_tjb_seller" => false,
                    "displaynick" => "displayNIck001",
                    "open_uid" => "adflajfaf"
                ],
            ],
        ];
    }

    public function taobao_item_promotion_rule_get(Request $request)
    {
        $item_id = $request->get('item_id');
        if ($item_id == '101100009') {
            $rules = [
                "item_promotion_rule" => [
                    [
                        "name" => "2024淘宝新势力活动（天猫）",
                        "message" =>
                            "该商品为2024淘宝新势力活动商品，当前时间段库存禁止修改",
                        "start_time" => "2024-11-12 00:00:00",
                        //"end_time" => "2024-11-12 12:00:00",
                        "end_time" => "2024-11-12 18:00:00",
                        "type" => "库存禁止修改规则",
                    ],
                ],
            ];
        } else {
            $rules = [];
        }
        return [
            "item_promotion_rule_get_response" => [
                "rules" => $rules,
                "effec" => true,
            ],
        ];
    }

    public function taobao_item_quantity_update()
    {
//        return [
//            "error_response" => [
//                "msg" => "Remote service error",
//                "code" => 50,
//                "sub_msg" => "非法参数",
//                "sub_code" => "isv.invalid-parameter",
//            ]
//        ];
//        return response([
//            'error_response' => [
//                "msg" => "Remote service error",
//                "sub_code" => "isv.ic_ic_save_inventory_to_ip_failed",
//                "code" => 15,
//                "request_id" => "16ktygdr3gkqy",
//                "sub_msg" => "IP_EDIT_LOCK_ACQUIRED_ERROR"
//            ]
//        ], 200);


//        return response([
//            'error_response' => [
//                'code' => 50,
//                'msg' => 'Remote service error',
//                'sub_code' => 'IC_UN_SUPPORT_ITEM_EDIT_QUANTITY',
//                'sub_msg' => '该商品为xxx活动商品，当前时间段库存禁止修改',
//            ]
//        ], 200);
//        return response([
//            'error_response' => [
//                'code' => 15,
//                'msg' => 'Remote service error',
//                'sub_code' => 'isv.error-backend-inventory-mode',
//                'sub_msg' => '此商品关联后端货品，库存变更请到货品中心编辑后端货品库存',
//            ]
//        ], 200);

        return [
            "item_quantity_update_response" => [
                "item" => [
                    "iid" => "569a64fce2e98bce187bcbbb4a4d262a",
                    "num_iid" => 5432112345,
                    "modified" => "2000-01-01 00:00:00",
                    "num" => 10,
                    "skus" => [
                        "sku" => [
                            [
                                "sku_id" => 'sku_id_123',
                                "modified" => "2009-11-04 15:24:43",
                                "quantity" => 1,
                            ],
                        ],
                    ],
                ],
            ],
        ];
    }

    // 查询订单备注列表
    public function taobao_trade_sellermemos_get(Request $request)
    {
        $operatorIds = [
            2208110852001, 2208110852002, 2208110852003
        ];
        $tid = $request->get('tid', '');
        $orderSellerMemos = [];
        foreach (range(0, random_int(2, 10)) as $key) {
            $orderSellerMemos[] = [
                "flag_id" => $key,
                "memo" => sprintf('订单备注：%s', Str::random(8)),
                "operator_id" => $operatorIds[$key % count($operatorIds)],
                "tid" => $tid,
                "timestamp" => sprintf('%s000%s', date('Ymd'), $key)
            ];
        }
        if ($tid == '2451087806001113479') {
            $orderSellerMemos = [[
                "flag_id" => 0,
                "memo" => '测试国补',
                "operator_id" => 100001,
                "tid" => $tid,
                "timestamp" => (int)(time() . '000')
            ]];
        }

        return [
            'trade_sellermemos_get_response' => [
                'memos' => [
                    'order_seller_memo' => $orderSellerMemos,
                ]
            ],
        ];
    }

    // 获取指定账户子账号的详细信息
    public function taobao_subuser_fullinfo_get(Request $request)
    {
        $subId = $request->get('sub_id', '');
        $operatorNames = [
            '2208110852001' => '张三',
            '2208110852002' => '李四',
            '2208110852003' => '王五',
        ];

        return [
            'subuser_fullinfo_get_response' => [
                'sub_fullinfo' => [
                    "sub_id" => $subId,
                    "employee_nickname" => $operatorNames[$subId] ?? '员工花名',
                    "employee_name" => $operatorNames[$subId] ?? '员工姓名',
                    "employee_id" => $subId,
                    "sub_nick" => $operatorNames[$subId] ?? '子账号用户名',
                    "user_nick" => $operatorNames[$subId] ?? '主账号用户名',
                    "work_location" => "杭州大厦",
                    "sex" => 1,
                    "sub_status" => 1,
                    "department_id" => 2222222,
                    "duty_level" => 3,
                    "sub_dispatch_status" => true,
                    "user_email" => "xiaowang@tmall.com",
                    "sub_owed_status" => true,
                    "duty_name" => "总裁",
                    "leader_id" => 123456,
                    "employee_num" => "111",
                    "parent_department" => 3333333,
                    "duty_id" => 44444444,
                    "entry_date" => "2000-01-01 00:00:00",
                    "user_id" => 654321,
                    "department_name" => "运营部",
                    "office_phone" => "0571-11234567",
                    "subuser_email" => "zhangsan@tmall.com"
                ],
            ],
        ];
    }

    public function taobao_trade_invoice_amount_get(Request $request)
    {
        $tid = $request->get('tid', '');
        if ($tid == '63062022082120377') {
            $consumer_invoice_amount = '18000';
            $platform_invoice_amount = '2000';
        } elseif ($tid == '63062022082120465') {
            $consumer_invoice_amount = '76062';
            $platform_invoice_amount = '1438';
        } elseif (substr($tid, 0, -3) == '2609798450726881') {
            $consumer_invoice_amount = '133000';
            $platform_invoice_amount = '0';
        } else {
            return response([
                'error_response' => [
                    'code' => 50,
                    'msg' => 'Remote service error',
                    'sub_code' => 'isv.invalid-parameter',
                    'sub_msg' => '非法参数'
                ]
            ], 200);
        }

        return [
            'trade_invoice_amount_get_response' => [
                'consumer_invoice_amount' => $consumer_invoice_amount,
                'platform_invoice_amount' => $platform_invoice_amount
            ]
        ];
    }

    // 获取单笔退款详情
    public function taobao_refund_get(Request $request)
    {
        $oid = '202505141537001';
        $orderSn = '20250626002';
        $refund_id = $request->get('refund_id', '');
        $quantity = 1;
        $unitPrice = 2976.06;
        $refundFee = 2976.06;
        $orderAmount = 7520;

        return [
            'refund_get_response' => [
                'refund' => [
                    "tid" => $orderSn,
                    "refund_id" => !empty($refund_id) ? $refund_id : date('YmdHis') . time(),
                    "alipay_no" => "2009101504179117",
                    "num" => $quantity,
                    "num_iid" => 4345345,
                    "oid" => $oid,
                    "refund_fee" => $refundFee, // 退款金额
                    "price" => $unitPrice, // 单价
                    "payment" => $orderAmount, // 交易总金额
                    "total_fee" => $orderAmount, // 订单总金额
                    "ypds_refund_type" => "0",
                    "ypds_refund_reason" => "不想要了",
                    "ypds_refund_supply_fee" => "0",
                    "refund_phase" => "onsale",
                    "address" => "杭州市西湖区华星路99号",
                    "buyer_nick" => "tbtest561",
                    "company_name" => "申通快递",
                    "advance_status" => 1,
                    "cs_status" => 1,
                    "attribute" => "{}",
                    "desc" => "hello world",
                    "created" => date('Y-m-d H:i:s'),
                    "good_return_time" => date('Y-m-d H:i:s'),
                    "modified" => date('Y-m-d H:i:s'),
                    "end_time" => date('Y-m-d H:i:s'),
                    "good_status" => "BUYER_NOT_RECEIVED", // BUYER_NOT_RECEIVED (买家未收到货) BUYER_RECEIVED (买家已收到货) BUYER_RETURNED_GOODS (买家已退货)
                    "has_good_return" => false, // 是否退货
                    "operation_contraint" => "refund_onweb",
                    "order_status" => "BUYER_RECEIVED",
                    "outer_id" => "ISBN-001",
                    "reason" => "退还邮费",
                    "refund_remind_timeout" => [
                        "exist_timeout" => true,
                        "remind_type" => 1,
                        "timeout" => date('Y-m-d H:i:s', strtotime('+3 day'))
                    ],
                    "refund_version" => 1411375308927,
                    "seller_nick" => "tbtest869",
                    "shipping_type" => "free",
                    "sid" => "123456789",
                    "sku" => "30004447689|颜色分类:军绿色;尺码:XS",
                    "split_seller_fee" => "1.25",
                    "split_taobao_fee" => "1.25",
                    "status" => "SUCCESS",
                    "title" => "天堂伞龙井茶",
                    "buyer_open_uid" => "324324324",
                    "ouid" => "iuwerkjhffd",
                    "combine_item_info" => [],
                    "dispute_type" => "REFUND",
                    "seller_open_uid" => "324324324",
                    "new_sku" => "5479148571308|颜色分类:米白+浅肤;尺码:XL",
                    "real_receiver_open_id" => "AAEnVKOdAOIduo9TH9hjf-zb",
                    "real_receiver_display_nick" => "这是一个昵称",
                ]
            ]
        ];
    }

    public function taobao_wlb_stores_baseinfo_get()
    {
        return [
            'wlb_stores_baseinfo_get_response' => [
                'store_info_list' => [
                    'store_info' => []
                ],
            ]
        ];
    }

    public function taobao_fenxiao_products_get(Request $request)
    {
        $page = $request->get('page_no', 1);

        $sku1 = [
            "cost_price" => "1189.00",
            "dealer_cost_price" => "1189.00",
            "id" => 5882404632875,
            "name" => "颜色分类:78277-IMCBI(老花配黑色）;",
            "outer_id" => "SKUA00001",
            "properties" => "1627207:39688913761",
            "quantity" => 0,
            "quota_quantity" => 0,
            "reserved_quantity" => 0,
            "standard_price" => "1189.00"
        ];
        $sku2 = [
            "cost_price" => "1068.50",
            "dealer_cost_price" => "1068.50",
            "id" => 5882404632876,
            "name" => "颜色分类:5504-IMRKI(卡其色）;",
            "outer_id" => "SKUA00001",
            "properties" => "1627207:39688913762",
            "quantity" => 0,
            "quota_quantity" => 0,
            "reserved_quantity" => 0,
            "standard_price" => "1068.50"
        ];

        $product = [
            "category_id" => "50012010",
            "city" => "常州",
            "cost_price" => "1189.00",
            "created" => "2025-07-15 14:44:27",
            "dealer_cost_price" => "1189.00",
            "desc_path" => "https://itemcdn.tmall.com/desc/icoss!0951719291938!11142407004",
            "description" => "<p><img src=\"https://img.alicdn.com/imgextra/i2/2219454014183/O1CN01LB7sfe1glrohfPqhM_!!2219454014183.jpg\" align=\"absmiddle\"></p> <p><img src=\"https://img.alicdn.com/imgextra/i3/2219454014183/O1CN01qFYeAc1glrogYqwen_!!2219454014183.jpg\" align=\"absmiddle\"></p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p><img src=\"https://img.alicdn.com/imgextra/i4/2219454014183/O1CN01PFRc8w1glromidA1e_!!2219454014183.jpg\" align=\"absmiddle\"></p> <p><img src=\"https://img.alicdn.com/imgextra/i3/2219454014183/O1CN01otfKgf1glromPALsW_!!2219454014183.jpg\" align=\"absmiddle\"></p> <p><img src=\"https://img.alicdn.com/imgextra/i1/2219454014183/O1CN01j09sS41glrosdGE3u_!!2219454014183.jpg\" align=\"absmiddle\"><img src=\"https://img.alicdn.com/imgextra/i4/2219454014183/O1CN01rw9DAh1glrommhCgq_!!2219454014183.jpg\" align=\"absmiddle\"><img src=\"https://img.alicdn.com/imgextra/i4/2219454014183/O1CN01LrQy6m1glrosKCwWJ_!!2219454014183.jpg\" align=\"absmiddle\"><img src=\"https://img.alicdn.com/imgextra/i4/2219454014183/O1CN01GlLUn21glrorZNDoW_!!2219454014183.jpg\" align=\"absmiddle\"><img src=\"https://img.alicdn.com/imgextra/i3/2219454014183/O1CN01dqTtQE1glrosKCXaA_!!2219454014183.jpg\" align=\"absmiddle\"><img src=\"https://img.alicdn.com/imgextra/i1/2219454014183/O1CN01Ta7g9Z1glrostwrPI_!!2219454014183.jpg\" align=\"absmiddle\"><img src=\"https://img.alicdn.com/imgextra/i1/2219454014183/O1CN01fLr2Zk1glrojXN9rD_!!2219454014183.jpg\" align=\"absmiddle\"><img src=\"https://img.alicdn.com/imgextra/i4/2219454014183/O1CN01gQOpfQ1glrok0XA3Z_!!2219454014183.jpg\" align=\"absmiddle\"><img src=\"https://img.alicdn.com/imgextra/i3/2219454014183/O1CN01TN6DN21glro4qnwkA_!!2219454014183.jpg\" align=\"absmiddle\"><img src=\"https://img.alicdn.com/imgextra/i4/2219454014183/O1CN01qyyTq01glro4eUSO2_!!2219454014183.jpg\" align=\"absmiddle\"></p>",
            "discount_id" => 0,
            "have_invoice" => false,
            "have_quarantee" => false,
            "input_properties" => "13021751:CBQ35-IMQRX;344943689:5600元;1627207:78277-IMCBI(老花配黑色）;1627207:颜色分类;1627207:5504-IMRKI(卡其色）;1627207:颜色分类;1627207:CBQ35-IMQRX(新款老花配黑色）;1627207:颜色分类;1627207:CBR31-IMY7H（新款卡其色）;",
            "is_authz" => "yes",
            "items_count" => 1,
            "modified" => "2025-08-04 17:26:56",
            "name" => "COACH/蔻驰经典印花PVC单肩斜挎手提化妆盒子包",
            "orders_count" => 0,
            "outer_id" => "196395875849",
            "pictures" => "https://img.alicdn.com/bao/uploaded/i1/2219454014183/O1CN01tk7p1b1glrosMYU5x_!!4611686018427380455-0-item_pic.jpg,https://img.alicdn.com/bao/uploaded/i1/2219454014183/O1CN01H63e1M1glrosunE0I_!!2219454014183.jpg,https://img.alicdn.com/bao/uploaded/i4/2219454014183/O1CN01Ud2h1u1glroraAEUW_!!2219454014183.jpg,https://img.alicdn.com/bao/uploaded/i1/2219454014183/O1CN01CeN06g1glromnd8jl_!!2219454014183.jpg,https://img.alicdn.com/bao/uploaded/i2/2219454014183/O1CN019WgjBb1glrorZDHwm_!!2219454014183.jpg",
            "pid" => 951719291938,
            "postage_type" => "seller",
            "productcat_id" => 34914034,
            "properties" => "20000:3889310;27074180:20213;20021:29228;1627207:39688913761;1627207:39688913762;1627207:39688913763;1627207:39688913764;8560225:828900456;13021751:39391344168;122216515:203870599;122216515:3315430;122216515:50288;122216515:29535;122276315:41713998;134942334:109101;137424339:41713998;148380063:852424991;344943689:86184788;568132093:20533",
            "property_alias" => "",
            "prov" => "江苏",
            "quantity" => 363,
            "quota_quantity" => 0,
            "reserved_quantity" => 0,
            "retail_price_high" => "1189.00",
            "retail_price_low" => "1189.00",
            "skus" => [
                'fenxiao_sku' => [
                    $sku1,
                    $sku2,
                ]
            ],
            "spu_id" => 8516884254,
            "standard_price" => "1189.00",
            "standard_retail_price" => "1189.00",
            "status" => "up",
            "trade_type" => "AGENT"
        ];

        return [
            'fenxiao_products_get_response' => [
                'products' => [
                    'fenxiao_product' => [
                        $product
                    ]
                ],
                'total_results' => $page > 1 ? 0 : 1,
                'request_id' => Str::random(16),

            ]
        ];
    }

    public function taobao_fenxiao_product_quantity_update(Request $request)
    {
        return [
            'fenxiao_product_quantity_update_response' => [
                'result' => true,
                'request_id' => Str::random(16),
            ]
        ];
    }

    // 是否可发起协商
    public function taobao_refund_negotiate_canapply(Request $request)
    {
        return [
            'refund_negotiate_canapply_response' => [
                "can_apply" => true,
                "negotiate_types" => [
                    'negotiation_type' => [
                        [
                            "negotiate_code" => 1,
                            "negotiate_desc" => "退款原因协商"
                        ]
                    ]
                ]
            ]
        ];
    }

    // 协商退货退款渲染
    public function taobao_refund_negotiatereturn_render(Request $request)
    {
        return [
            'refund_negotiatereturn_render_response' => [
                "apply_tips" => "与买家协商退货退款，买家接受后将自动同意退款申请",
                "refund_version" => 1409231007325,
                "reason_list" => [
                    "reason" => [
                        [
                            "reason_id" => 112233,
                            "reason_text" => "不喜欢"
                        ]
                    ]
                ],
                "max_refund_fee" => [
                    "max_refund_fee" => 12
                ],
                "address_list" => [
                    "address" => [
                        [
                            "address_id" => 123,
                            "receiver_name" => "收件人",
                            "post_code" => "311100",
                            "mobile" => "131xxxxxxxx",
                            "country_name" => "中国",
                            "province_name" => "浙江省",
                            "city_name" => "杭州市",
                            "area_name" => "余杭区",
                            "town_name" => "五常街道",
                            "address_detail" => "阿里巴巴西溪B区",
                            "division_code" => "112233"
                        ]
                    ]
                ],
                "negotiate_type" => [
                    "negotiate_code" => 17,
                    "negotiate_desc" => "协商售后信息",
                    "negotiate_text" => "推荐话术"
                ],
                'negotiate_types' => [
                    'negotiation_type' => [
                        [
                            "negotiate_code" => 17,
                            "negotiate_desc" => "协商售后信息"
                        ]
                    ]
                ],
                "refuse_reason_list" => [
                    "reason" => [
                        [
                            "reason_id" => 123,
                            "reason_text" => "商品退回后才能退款，请修改为退货退款"
                        ]
                    ]
                ]
            ]
        ];
    }

    // 协商退货退款
    public function taobao_refund_negotiatereturn(Request $request)
    {
        return [
            'refund_negotiatereturn_response' => []
        ];
    }

    public function trace_record(Request $request)
    {
        return [];
    }

    public function tmall_exchange_get(Request $request)
    {
        return [
            "tmall_exchange_get_response" => [
                "result" => [
                    "message" => "ok",
                    "msg_code" => "10000",
                    "success" => true,
                    "exchange" => [
                        "dispute_id" => "260979845072688111103",
                        "alipay_no" => "2609798450726881111",
                        "refund_phase" => "yes",
                        "reason" => "七天无理由退换货",
                        "desc" => "无理由换货",
                        "status" => "换货待处理",
                        "good_status" => "",
                        "created" => "2000-01-01 00:00:00",
                        "modified" => "2000-01-01 00:00:00",
                        "time_out" => "2000-01-01 00:00:00",
                        "seller_nick" => "测试店铺",
                        "buyer_nick" => "f**",
                        "buyer_open_uid" => "AAFNt7DQAA_spZaeCv6eZuw4",
                        "attributes" => "{}",
                        "exchange_sku" => "TBSKUA00002",
                        "bought_sku" => "TBSKUA00001",
                        "num" => 1,
                        "title" => "测试商品A 绿色",
                        "buyer_logistic_name" => "",
                        "buyer_logistic_no" => "",
                        "seller_logistic_name" => "",
                        "seller_logistic_no" => "",
                        "price" => "1330",
                        "buyer_name" => "李**",
                        "buyer_phone" => "***********",
                        "buyer_address" => "上海^^^上海市^^^徐汇区^^^田林街道 田*街道中**路******号***室",
                        "oaid" => "1e2w9A5JqbsMb3UATPhl6QXk59ictuMtTejqpMp9TMfyH1RZwYvZnUAVVYeAyKnSXOlbibSIO",
                        "refund_version" => 1758853562
                    ],
                ],
            ],
        ];
    }

    public function taobao_top_oaid_decrypt(Request $request)
    {
        $queryList = $request->get('query_list', '{}');
        $queryList = json_decode($queryList, true);
        $query = $queryList ? $queryList[0] : null;
        $receiver = null;
        if ($query) {
            $receiver = [
                "tid" => $query['tid'],
                "oaid" => $query['oaid'],
                "name" => "李四",
                "phone" => "",
                "mobile" => "13012345678-1234",
                "country" => "中国",
                "state" => "上海",
                "city" => "上海市",
                "district" => "徐汇区",
                "town" => "田林街道",
                "address_detail" => "田林街道中环路1024号202室",
                "matched" => true,
                "secret_no_expire_time" => "2025-06-16 00:00:00",
                "privacy_protection" => true,
                "desensitize_rule" => "DECRYPTION_DISABLED_BY_ORDERCLOSED",
            ];
        }

//        return [
//            "error_response" => [
//                "msg" => "Remote service error",
//                "code" => 50,
//                "sub_msg" => "当日解密订单数量已超过额度",
//                "sub_code" => "isv.decryption-quota-exceeded",
//            ]
//        ];
        if ($receiver) {
            return [
                'top_oaid_decrypt_response' => [
                    'receiver_list' => [
                        'receiver' => [
                            $receiver
                        ]
                    ]
                ]
            ];
        } else {
            return [
                "error_response" => [
                    "msg" => "Remote service error",
                    "code" => 50,
                    "sub_msg" => "非法参数",
                    "sub_code" => "isv.invalid-parameter",
                ]
            ];
        }
    }
}
